﻿#include "LevelSelectTableLayer.h"
#include "VisibleRect.h"
#include "RectLayout.h"
#include "HelloWorldScene.h"
#include "GameLevelScene.h"
USING_NS_CC;

bool LevelSelectTableLayer::init()
{
	bool bRet = false;
	do 
	{		
		//////////////////////////////////////////////////////////////////////////
		// super init first
		//////////////////////////////////////////////////////////////////////////
		CC_BREAK_IF(! CCLayer::init());

		// schedule(schedule_selector(LevelSelectTableLayer::update));
		CCSize winSize = CCDirector::sharedDirector()->getWinSize();
		CCSize layerSize = CCSize::CCSize(200,200);

		CCMenuItemImage *pLevelMenuItem = CCMenuItemImage::create(
			"images/interface/Button.png",
			"images/interface/ButtonSelected.png",
			this,
			menu_selector(LevelSelectTableLayer::menuClickedCallback));
		CC_BREAK_IF(! pLevelMenuItem);

		CCMenu* pMenu = CCMenu::create(pLevelMenuItem, NULL);

		pMenu->setAnchorPoint(RectLayout::Center());
		pMenu->setPosition(VisibleRect::center());
		this->addChild(pMenu);

		CCLabelTTF* pLabel = CCLabelTTF::create("Start Level", "Arial", 18);
		CC_BREAK_IF(! pLabel);

		pLabel->setAnchorPoint(RectLayout::Center());
		pLabel->setPosition(VisibleRect::center());
		this->addChild(pLabel);

		bRet = true;
	} while (0);

	return bRet;
}

void LevelSelectTableLayer::menuClickedCallback( CCObject* pSender )
{
	CCDirector::sharedDirector()->replaceScene(CCTransitionFlipX::create(0.2f, GameLevelScene::scene()));
}
